<?php

class App_Model_DbTable_User_Account_Base extends Ext_Db_Table  
{  
    /** Table name */  
    protected $_name = 'user_account_base';
    
    private static $_userAccountBaseRow = array();
    
    public function getRowByUserId($userId)
    {
        if(!$userId)
        {
            return "";
        }
        
        if(isset(self::$_userAccountBaseRow['userId'][$userId]))
        {
            return self::$_userAccountBaseRow['userId'][$userId];
        }
        
        $db = $this->getAdapter();
        $safe = $db->quoteInto(" userId = ? ", $userId);
        $row = $this->fetchRow($safe);
        if (!$row) {
            return "";
        }
        $_userAccountBaseRow = $row->toArray();

        self::$_userAccountBaseRow['userId'][$userId] = $_userAccountBaseRow;
        
        return $_userAccountBaseRow;
    }
    
    public function addNew($inputArray)
    {
        $sql_data_array = array();
        if(array_key_exists('userId', $inputArray)) $sql_data_array['userId'] = $inputArray['userId'];
        if(array_key_exists('password', $inputArray)) $sql_data_array['password'] = $inputArray['password'];
        if(!$sql_data_array)
        {
            return "";
        }
        
        try {
            $rows_affected = $this->insert($sql_data_array);
            $last_insert_id = $this->getAdapter()->lastInsertId();
        }catch (Exception $e){
            trigger_error($e->getMessage(), E_USER_WARNING);
        }
        return $last_insert_id;
    }
    
    public function addOld($inputArray, $userId)
    {
        $sql_data_array = array();
        if(array_key_exists('password', $inputArray)) $sql_data_array['password'] = $inputArray['password'];
        if(!$sql_data_array)
        {
            return "";
        }
        
        try {
            $db = $this->getAdapter();
            $where = $db->quoteInto(" userId = ? ", $userId);
            $rows_affected = $this->update($sql_data_array, $where);
        }catch (Exception $e){
            trigger_error($e->getMessage(), E_USER_WARNING);
        }
        
        return "";
    }
    
}  

